-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First implementation for two endpoints. #1
Conversation
@@ -0,0 +1,13 @@ | |||
default: test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add for CI:
SHELL=/bin/bash
export PATH:=/usr/local/go/bin:~/go/bin/:$(PATH)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the SHELL variable, but PATH under discussion :) We will use actions, so maybe we don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, lint checks work fine without additional PATH. I'll check it with unit tests.
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func ErrorHandle() gin.HandlerFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think better to make like this:
var (
// ErrInternal is an error for when an internal service fails to process the request
ErrInternal = errors.New("internal error")
// ErrDataNotFound is an error for when requested data is not found
ErrDataNotFound = errors.New("data not found")
// ErrNoUpdatedData is an error for when no data is provided to update
ErrNoUpdatedData = errors.New("no data to update")
// ErrConflictingData is an error for when data conflicts with existing data
ErrConflictingData = errors.New("data conflicts with existing data in unique column")
// ErrInvalidCredentials is an error for when the credentials are invalid
ErrInvalidCredentials = errors.New("invalid email or password")
// ErrUnauthorized is an error for when the user is unauthorized
ErrUnauthorized = errors.New("user is unauthorized to access the resource")
)
var errorStatusMap = map[error]int{
ErrInternal: http.StatusInternalServerError,
ErrDataNotFound: http.StatusNotFound,
ErrConflictingData: http.StatusConflict,
ErrInvalidCredentials: http.StatusUnauthorized,
ErrUnauthorized: http.StatusUnauthorized,
}
func HandleError(ctx *gin.Context, err error) {
statusCode, ok := errorStatusMap[err]
if !ok {
statusCode = http.StatusInternalServerError
}
errRsp := errorResponse(errMsg)
ctx.JSON(statusCode, errRsp)
}
func errorResponse(errMsgs []string) errorResponse {
return errorResponse{
Success: false,
Messages: errMsgs,
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the error file will be soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should build on V2 to be compatible with the V1 API, not simply move Python code to Golang. If we are just moving code, we can merely use Cython to speed up the original SD2 or further optimize on top of SD2. - we could do better.
And this database design, like I said before, can lead to performance issues.
Don't worry, unfortunately we can't change DB before changing backend, and we should keep backward compatibility first. We will do a lot with schemas a bit later. Please check all endpoints, requests, responses. |
just write Database Migration Code ↓ https://github.com/Aloento/StatusDashboard/blob/master/Services/Status.cs#L21 |
About the DatabaseI agree with something Vladi once said, “Later is never.” So, I strongly recommend developing the new database structure now. We don't need to consider compatibility with the old backend because the new backend will run on a new database instance. We only need to perform a one-time data migration when going live, and this process is quite simple. Our test instance can directly use the migrated data for demonstration. The data in my SD3 C# version is migrated in real-time, and it already supports complete and rapid migration. If it’s too complicated to write in Golang, I can modify the C# migration code to adapt to our new backend since migration is a one-time task. I’ve attached my designed database structure, hoping it will help you all. OpenAPI v2Front-end requests are cached, and only a fine-grained API can maximize front-end caching. /v2/EventWe do not call it an incident because a maintenance event is not an incident, so now we use Event. GET /v2/Eventslist all event ids GET /v2/Event/{id}get event entity by id with related region ids, related component ids GET /v2/Event/{id}/UpdatesReturn all update entities of the event GET /v2/Events/Activereturn all Current Events ids POST /v2/EventCreate a new event PATCH /v2/Event/{id}Update event by patch method and push new update entity at the same time
POST /v2/Event/{id}/Splitby given the [{Service_Id}, {Region_Id}] pairs, split the event into two events. POST /v2/Event/MergeMerge two events into one event by providing the two event IDs, new event titles, descriptions, etc. /v2/RegionGET /v2/RegionsList all region entities Not contain any component data or event data or category data GET /v2/Region/{id}/CategoriesReturn all categories ids present in the region /v2/CategoryGET /v2/CategoriesList all categories entity Not contain any component data or event data GET /v2/Category/{id}/ServicesReturn all component ids present in the category /v2/ServiceGET /v2/Serviceslist all component ids GET /v2/Service/{id}get component entity by id GET /v2/Service/{id}/EventsReturn all event ids present in the component /v2/AvailabilityGET /v2/Availability/{Service_Id}/{Region_Id}return the availability of the component in the last 6 months |
package app | ||
|
||
const ( | ||
v1Group = "v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/api/v1
is mandatory
- name: components | ||
description: Operations about components | ||
paths: | ||
/v1/components: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thought /api
was implemented elsewhere, but it's not.
So it has to be modified.
First implementation for SD3.